<?php
/**
 * Date: 2017/11/10
 * Time: 10:08
 * Author: zeronlee
 */

namespace App\Http\Controllers\Api\V1\Announce;
use App\Http\Controllers\Api\V1\BaseController;
use App\Http\Controllers\Api\V1\TransformerController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;


class AnnounceController extends BaseController
{

    public function index(Request $request)
    {
        $last = DB::table('announce')
            ->select('sn', 'id','title','created_at')
            ->where('is_publish','=', 1)
            ->orderBy('id','desc')
            ->paginate(10);

        return   $this->returnArray($last->toArray());
    }

    /**公告详情
     * @param Request $request
     */
    public function det(Request $request)
    {
        $id = intval($request->aid);
        if ($id) {
            $last = DB::table('announce')
                ->leftJoin('users', 'users.id', '=', 'announce.user_id')
                ->select('announce.id','announce.sn','announce.title','announce.description','announce.content','announce.created_at')
                ->where('announce.id', $id)
                ->first();
        }else{
            return $this->response->error("id not given",'404');
        }
        return   $this->returnArray($last);
    }
    /**首页最新六条
     * @param Request $request
     */
    public function topSix(Request $request)
    {

        $last = DB::table('announce')
                ->select('sn', 'id','title','created_at')
                ->where('is_publish','=', 1)
                ->limit(6)
                ->orderBy('id','desc')
                ->get();
        return   $this->returnArray($last->toArray());
    }

}